<template>
    <div>

    </div>
</template>

<script>
    export default {
        data() {
            return {};
        },

        methods: {
          check() {
            //获取选中的行
            const ids = this.$store.state.edit.ids;
            const selectedData = this.$store.state.main.selectedData;
            if (selectedData.length < 2) {
              this.$message.error("请至少勾选2条记录！");
              return;
            }

            let allServeCompanyIdMap = new Map();
            let allCurrencyRateMap = new Map();
            let companyBankIdMap = new Map();

            for (let i = 0; i < selectedData.length; i++) {
              let item = selectedData[i];
              allServeCompanyIdMap.set(item.serveCompanyId, item.serveCompanyId);
              companyBankIdMap.set(item.companyBankId, item.companyBankId);
              let financeRates = item.financeRates;
              for (let j = 0; j < financeRates.length; j++) {
                let financeRateObj = financeRates[j];
                let sourceCurrency = financeRateObj.sourceCurrency;
                if (allCurrencyRateMap.get(sourceCurrency)) {
                  let originalRate = allCurrencyRateMap.get(sourceCurrency);
                  if (financeRateObj.rate != originalRate) {
                    this.$message.error("汇率不同不允许合并记账！");
                    return;
                  }
                } else {
                  allCurrencyRateMap.set(sourceCurrency, financeRateObj.rate);
                }
              }
            }
            if (allServeCompanyIdMap.size > 1) {
              this.$message.error("相同服务商的付款申请才可合并记账！");
              return;
            }
            if (companyBankIdMap.size > 1) {
              this.$message.error("付款账号不同不允许合并记账！");
              return;
            }
            //校验通过，跳转至记账页面
            let url = "#/blank/finance__account__forpayapply?payApplyIds=" + ids;
            window.open(url);
          }
        },

        mounted() {
          this.check();
        }
    };
</script>


<style>

</style>
